import 'package:flutter/material.dart';
import 'package:moose_app/core/model/chat_message_model.dart';
import 'package:moose_app/ui/screens/gallery/gallery_screen.dart';
import 'package:moose_app/ui/values/values.dart';
import 'package:moose_app/ui/widgets/chat/chat_message_receiver.dart';
import 'package:moose_app/ui/widgets/chat/chat_message_snder.dart';

class ATHChatMessageItem extends StatelessWidget {
  final ATHChatMessageModel messageModel;

  ATHChatMessageItem({@required this.messageModel});

  @override
  Widget build(BuildContext context) {
    return Container(
        margin: EdgeInsets.symmetric(horizontal: kSize20, vertical: kSize20),
        child: _createItemByChatMessageType(context));
  }

  Widget _createItemByChatMessageType(BuildContext context) {
    return messageModel.ownerType == ATHOwnerType.sender
        ? ATHChatMessageSender(
            messageModel: messageModel,
            imageMessageTap: () {
              _open(context);
            },
          )
        : ATHChatMessageReceiver(
            messageModel: messageModel,
            imageMessageTap: () {
              _open(context);
            },
          );
  }

  void _open(BuildContext context) {
    Navigator.push(
      context,
      PageRouteBuilder(
        pageBuilder: (BuildContext context, Animation<double> animation,
                Animation<double> secondaryAnimation) =>
            GalleryScreen(
          galleryItems: galleryItems,
          backgroundDecoration: BoxDecoration(color: Colors.white),
          initialIndex: 0,
          scrollDirection: Axis.horizontal,
        ),
      ),
    );
  }
}
